from PJKuGou import Public_kugo
from PJKuGou import Public_kugo
from PJKuWo import Public_kuwo


class SearchKWMusic:

    def search(self, keyword, page, pagesize, platform):
        '''
        :param keyword: 歌名
        :param page: 当前页
        :param pagesize: 总页数
        :param platform: 平台名称
        :return: 歌曲数据
        '''

        if (platform == "kugou"):
            cx = Public_kugo()
            total, search = cx.Search(keyword, page, pagesize)
            pass
        if (platform == "kuwo"):
            cx = Public_kuwo()
            total, search = cx.Search(keyword, page, pagesize)
            pass



        list = []

        for data in search:
            list.append({
                # 歌曲ID
                "img_href":  'https://img2.kuwo.cn/star/albumcover/' + data['web_albumpic_short'] if data['web_albumpic_short'] != ''
                else "https://img1.kuwo.cn/star/starheads/" + data['web_artistpic_short'],
                "id": data['DC_TARGETID'],
                # 歌曲名称
                "song_name": data['gqm'],
                # 演唱者
                "gs": data["ARTIST"],
                "hash": data['DC_TARGETID'],
                # 是否免费播放 '1' 则收费， '0' 则免费
                "vip": 'vip' if data['payInfo']['listen_fragment'] == '1' else '',
            })

        return {
            "head": None,
            "list": list,
            "total": total
        }
